package com.kbt.util.tool;

import android.os.CountDownTimer;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 * @author zhgk
 * @package: com.kbt.util.tool
 * @TODO: <请描述这个类是干什么的>
 * @data: 2015/8/15 16:47
 * @version: V1.0
 */
public class TimeCountUtil extends CountDownTimer {
    private View v;

    public TimeCountUtil(View v, long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);//参数依次为总时长,和计时的时间间隔
        this.v = v;
    }

    @Override
    public void onFinish() {//计时完毕时触发
        if (v instanceof TextView) {
            ((TextView) v).setText("获取验证码");
        } else if (v instanceof Button) {
            ((Button) v).setText("获取验证码");
        }

        v.setClickable(true);
    }

    @Override
    public void onTick(long millisUntilFinished) {//计时过程显示
        if (v instanceof TextView) {
            ((TextView) v).setText("重新获取(" + millisUntilFinished / 1000 + ")");
        } else if (v instanceof Button) {
            ((TextView) v).setText("重新获取(" + millisUntilFinished / 1000 + ")");
        }
        v.setClickable(false);

    }

}
